using UnityEngine;
using System.Collections;

public class WowadiusPlayerAction : MonoBehaviour
{
	#region Input params
	public GameObject BulletPref = null;
	#endregion

	#region Private fields
	private bool _canShoot = true;
	private float _shootTimeCount = 0f;
	#endregion

	// Use this for initialization
	void Start ()
	{		
		
	}

	// Update is called once per frame
	void FixedUpdate ()
	{
		updateShooting ();
	}

	private void updateShooting ()
	{
		//Increase shoot time count if is waiting
		if (!_canShoot) {
			_shootTimeCount += Time.deltaTime;
		}
		//Ready for next shot
		if (_shootTimeCount >= WowadiusGlobal.CurrentPlayerStats.RateOfFire) {
			_canShoot = true;
			_shootTimeCount = 0;
		}
		//Shoot!
		if (Input.GetButton ("Fire1") && _canShoot) {
			Vector3 bulletStartPos = transform.position + new Vector3 (Random.Range(-0.3f, 0.3f), 0.6f, 0);
			Instantiate (BulletPref, bulletStartPos, Quaternion.identity);
			_canShoot = false;
		}
		
	}
}
